package org.itboys.core.controller.front.area;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.admin.service.lasted.SundayAreaService;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2018/12/20
 * 描述：
 */
@Controller
@RequestMapping("/sunday/mobile/area")
@Api(value = "area", description = "地区")
public class SundayMobileAreaController extends BaseController {
    @Autowired
    private SundayAreaService areaService;

    /**
     * @param request
     * @param response
     * @param //是否需要乡镇数据。如果是含有乡镇数据，不建议使用此方法
     */
    @RequestMapping(value = "/getTree", method = RequestMethod.POST)
    @ApiOperation(value = "获取所有")
    public void getAreaTree(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        ResponseMessage.success(areaService.getAreaTree(false));
    }

    /**
     * 获取省
     *
     * @param request
     * @param response
     */

    @RequestMapping(value = "/getProvince", method = RequestMethod.POST)
    @ApiOperation(value = "获取省份")
    public void getProvince(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        ResponseMessage.success(areaService.getProvince());
    }

    /**
     * 获取市
     *
     * @param request
     * @param response
     * @param provinceId
     */
    @RequestMapping(value = "/getCity", method = RequestMethod.POST)
    @ApiOperation(value = "获取城市")
    public void getCity(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "provinceId", required = true) Long provinceId
    ) {
        ResponseMessage.success(areaService.getCity(provinceId));
    }

    /**
     * 获取区县
     *
     * @param request
     * @param response
     * @param cityId
     */
    @RequestMapping(value = "/getDistrict", method = RequestMethod.POST)
    @ApiOperation(value = "获取地区")
    public void getDistrict(
            HttpServletRequest request,
            HttpServletResponse response,
            @RequestParam(value = "cityId", required = true) Long cityId
    ) {
        ResponseMessage.success(areaService.getDistrict(cityId));
    }

    @RequestMapping(value = "/getCityByPy", method = {RequestMethod.POST})
    @ApiOperation(value = "获取市（拼接拼音首字母）")
    public void getCityByPy(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "随机数。【参与签名】") @RequestParam(value = "nonce", required = true) String nonce,
            @ApiParam(value = "签名") @RequestParam(value = "sign", required = true) String sign
    ) {
        ResponseMessage.success(areaService.getCityByPy());
    }
}
